package top.kaoshanji.p3ch04a;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import top.kaoshanji.p3ch04a.mapper.EmployeeMapper;
import top.kaoshanji.p3ch04a.model.Employee;
import top.kaoshanji.p3ch04a.util.SqlSessionUtil;

/**
 * @author kaoshanji
 * ^_^
 * create time 2025/4/19 19:35
 */
public class EmployeeMapperTest {

    /**
     * 代码清单test-p3ch04a-95页a：根据员工id查询员工和部门信息（association标签之关联嵌套映射）
     */
    @Test
    public void testFindEmployeeById1() {
        SqlSession sqlSession = null;
        try {
            sqlSession = SqlSessionUtil.getSqlSession();
            EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class);

            Employee employee = employeeMapper.findEmployeeById1(1);
            System.out.println(employee);

        } finally {
            SqlSessionUtil.closeSqlSession(sqlSession);
        }
    }

    /**
     * 代码清单test-p3ch04a-97页a：根据员工id查询员工和部门信息（association标签之关联嵌套查询）
     */
    @Test
    public void testFindEmployeeById2() {
        SqlSession sqlSession = null;
        try {
            sqlSession = SqlSessionUtil.getSqlSession();
            EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class);

            Employee employee = employeeMapper.findEmployeeById2(1);
            System.out.println(employee);

        } finally {
            SqlSessionUtil.closeSqlSession(sqlSession);
        }
    }

}
